package com.chanceit.ssss.dialog;

import java.util.Calendar;

import android.app.DatePickerDialog;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.DatePicker;
import android.widget.TextView;

public class DatePickDialogImpOnclick implements OnClickListener {
	Calendar calendar = Calendar.getInstance();
	private DatePickerDialog dialog;

	public DatePickDialogImpOnclick(final TextView view) {
		DatePickerDialog.OnDateSetListener dateListener = new DatePickerDialog.OnDateSetListener() {
			@Override
			public void onDateSet(DatePicker datePicker, int year, int month,
					int dayOfMonth) {
				TextView editText = view;
				// Calendar月份是从0开始,所以month要加1
				String monthString = (month + 1) < 10 ? "0" + (month + 1)
						: ("" + (month + 1));
				String dayOfMonthString = dayOfMonth < 10 ? "0" + (dayOfMonth)
						: ("" + (dayOfMonth));
				editText.setText("" + year + "-" + monthString + "-"
						+ dayOfMonthString);
			}
		};
		dialog = new DatePickerDialog(view.getContext(), dateListener,
				calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
				calendar.get(Calendar.DAY_OF_MONTH));
	}

	@Override
	public void onClick(View v) {
		dialog.show();
	}

}
